package com.example.blogsystem.mapper;

import com.example.blogsystem.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 获取博客列表
     */
    @Select("select * from blog where delete_flag = 0 order by create_time desc")
    List<BlogInfo> selectAllBlog();
    /**
     * 添加博客
     */
    @Insert("insert into blog (title,content,user_id) values(#{title},#{content},#{userId})")
    Integer addBlog(BlogInfo blogInfo);
    /**
     * 更新博客
     */

    Integer updateById(BlogInfo blogInfo);
    /**
     * 删除博客
     */
    @Update("update blog set delete_flag = 1 where id = #{id}")
    Integer deleteById(Integer id);
    /**
     * 根据id查博客内容
     */
    @Select("select * from blog where id = #{id}")
    BlogInfo queryById(Integer id);

    /**
     * 统计博客总数
     */
    @Select("select count(id) from blog where delete_flag = 0")
    Integer countBlog();
}
